<?php
    $auth = Auth::getAuth('current_user');
    $get_info = Library::get_info();
    $db = new Database();
    $fs = new Functions();
    $Campaign_Functions = new Campaign_Functions();
    
?>
<div class="content">
    <!--- Bread Crumbs Menu -->
    <div class="breadLine">
        <ul class="breadcrumb">
            <li><a href="/">Admin</a> <span class="divider">></span></li>
            <li class="active"><a href="/">User</a> <span class="divider">></span></li>     
            <li class="active"><?php echo Config::get_page(); ?></li>
        </ul>
        <?php
            //echo $this->setLayout("breadcrumbs_right_menu");
        ?>
    </div>

   <div class="workplace">

        <div class="row-fluid">
            <div class="span12">
                <div class="head clearfix">
                    <div class="isw-calendar"></div>
                        <h1><?php echo Config::get_page(); ?></h1>
                    </div>
                    
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="widget">
                                <div class="head dark">
                                    <div class="icon title_icon"><i class="fa fa-list"></i></div>
                                    <h2>List of Campaign Planner</h2>
                                </div>                        
                                <div class="block-fluid">
                                    <div style="padding: 5px;" class="text-right">
                                        <button class="btn btn-small trigger_campaign_btn tip" data-action="campaign_planner" data-click-type="btn_approve" data-type="confirm" type="button" data-original-title="Confirm this campaign.">Confirm</button>
                                        <button class="btn btn-small trigger_campaign_btn tip" data-action="campaign_planner" data-click-type="btn_return" data-type="return" type="button" data-original-title="Return this campaign.">Move</button>
                                    </div>
                                    <!--<input type="text" id="campaign_planner" />-->
                                    <table class="tb_brochure " cellpadding="0" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <th><input type="checkbox" class="checkall selectAll" data-action="campaign_planner"/></th>
                                                <th width="25%">Campaign By</th>
                                                <th width="20%">Title</th>
                                                <th width="20%">Description</th>
                                                <th width="20%">Campaign</th>
                                                <th width="15%" class="TAC">Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
                                                // Approve Campaign By the Brand Manager
                                                $tb_campaign = $db->tbl_name(TB_CAMPAIGN);
                                                $tb_users = $db->tbl_name(TB_USERS);
                                                $tb_accounts = $db->tbl_name(TB_ACCOUNTS);
                                                $tb_brand_category = $db->tbl_name(TB_BRAND_CATEGORY);
                                                $query = $db->query("
                                                    SELECT *,c.id as camID FROM $tb_campaign c 
                                                    LEFT JOIN $tb_users u ON c.user_id=u.id
                                                    LEFT JOIN $tb_accounts a ON u.account_id=a.id
                                                    WHERE c.campaign_status_id = {$db->escape('1')}
                                                    ","array");
                                                
                                                // Validate if the current user is a brand manager
                                                if($get_info['info']->department == "15"){
                                                
                                                    foreach($query as $data){
                                                        $encrypted_camp_id = $fs->base_encode_decode("encrypt", $data['camID']);
                                                        
                                                        $arr = array("campaign_title"        =>  $data['title'],
                                                                    "campaign_id"      =>  $data['campaign_list_id'],
                                                                    "campaign_description"   =>  $data['description']);
                                            ?>
                                                        <tr id="camp_<?php echo $encrypted_camp_id; ?>" data-json="<?php echo htmlentities(json_encode($arr)); ?>">
                                                            <td><input type="checkbox" class="selectCheckBox" data-action="campaign_planner" name="select[]" data-id="<?php echo $encrypted_camp_id; ?>"/></td>
                                                            <td><a href="#"><?php echo $data['first_name'] . " " . $data['last_name']; ?></a></td>
                                                            <td><?php echo $data['title']; ?></td>
                                                            <td><?php echo $Campaign_Functions->reload_selected_campaign($data['campaign_list_id']); ?></td>
                                                            <td><?php echo $fs->truncateStringWords($data['description'],50); ?></td>
                                                            <td class="TAC" data-id="<?php echo $encrypted_camp_id; ?>">
                                                                <a class="trigger_campaign tip cursor" data-type="confirm" data-original-title="Confirm this campaign."><span class="icon-ok"></span></a> 
                                                                <a class="trigger_campaign tip cursor" data-type="return" data-original-title="Return this campaign."><span class="fa fa-mail-reply" style="color: #000;font-size: 12px;"></span></a>
                                                            </td>
                                                        </tr>
                                            <?php
                                                    }
                                                }
                                            
                                            ?>
                                        </tbody>
                                    </table>   
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>    
        </div>

   </div>

</div> 